package org.wattdepot.cli.commands;

import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

/**
 * This class tests the change server command of the Command
 * Line Interface's actual methods.
 * 
 * @author David Mau
 */
public class TestCommandChangeServer {

  /**
   * Tests normal operation of the change server command.
   */
  @Test
  public void testChangeServer() {
    // Create a new change server command object
    ChangeServerCommand command = new ChangeServerCommand(null);
    // Create a new list to store the args
    List<String> args = Arrays.asList( "http://dummyserver.org/" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );
    // Make sure that the command is returning the error properly
    assertTrue("Checking normal change server operation with a dummy argument", 
        sourceOutput.contains(WattDepotCliCommand.serverChange));
  }
  
  /**
   * Tests to see if the change server command can handle excess arguments.
   */
  @Test
  public void testExcessArguments() {
    // Create a new change server command object.
    ChangeServerCommand command = new ChangeServerCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1", "2");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking excess change server argument handling", 
        sourceOutput.contains(WattDepotCliCommand.tooManyArguments));
  }
  
  /**
   * Tests to see if the change server command can handle not enough arguments.
   */
  @Test
  public void testFewArguments() {
    // Create a new change server command object.
    ChangeServerCommand command = new ChangeServerCommand(null);
    // Create a new List to store the args
    List<String> args = new ArrayList<String>();
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking change server handling not enough arguments", 
        sourceOutput.contains(WattDepotCliCommand.missingArguments));
  }
}
